package cn.iocoder.yudao.module.vos.controller.admin.secretaccountproductprice;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.vos.controller.admin.secretaccountproductprice.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.secretaccountproductprice.SecretAccountProductPriceDO;
import cn.iocoder.yudao.module.vos.service.secretaccountproductprice.SecretAccountProductPriceService;

@Tag(name = "管理后台 - 全局产品定价（产品权限唯一 → 价格）")
@RestController
@RequestMapping("/vos/secret-account-product-price")
@Validated
public class SecretAccountProductPriceController {

    @Resource
    private SecretAccountProductPriceService secretAccountProductPriceService;

    @PostMapping("/create")
    @Operation(summary = "创建全局产品定价（产品权限唯一 → 价格）")
    @PreAuthorize("@ss.hasPermission('vos:secret-account-product-price:create')")
    public CommonResult<String> createSecretAccountProductPrice(@Valid @RequestBody SecretAccountProductPriceSaveReqVO createReqVO) {
        return success(secretAccountProductPriceService.createSecretAccountProductPrice(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新全局产品定价（产品权限唯一 → 价格）")
    @PreAuthorize("@ss.hasPermission('vos:secret-account-product-price:update')")
    public CommonResult<Boolean> updateSecretAccountProductPrice(@Valid @RequestBody SecretAccountProductPriceSaveReqVO updateReqVO) {
        secretAccountProductPriceService.updateSecretAccountProductPrice(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除全局产品定价（产品权限唯一 → 价格）")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('vos:secret-account-product-price:delete')")
    public CommonResult<Boolean> deleteSecretAccountProductPrice(@RequestParam("id") String id) {
        secretAccountProductPriceService.deleteSecretAccountProductPrice(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除全局产品定价（产品权限唯一 → 价格）")
                @PreAuthorize("@ss.hasPermission('vos:secret-account-product-price:delete')")
    public CommonResult<Boolean> deleteSecretAccountProductPriceList(@RequestParam("ids") List<String> ids) {
        secretAccountProductPriceService.deleteSecretAccountProductPriceListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得全局产品定价（产品权限唯一 → 价格）")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('vos:secret-account-product-price:query')")
    public CommonResult<SecretAccountProductPriceRespVO> getSecretAccountProductPrice(@RequestParam("id") String id) {
        SecretAccountProductPriceDO secretAccountProductPrice = secretAccountProductPriceService.getSecretAccountProductPrice(id);
        return success(BeanUtils.toBean(secretAccountProductPrice, SecretAccountProductPriceRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得全局产品定价（产品权限唯一 → 价格）分页")
    @PreAuthorize("@ss.hasPermission('vos:secret-account-product-price:query')")
    public CommonResult<PageResult<SecretAccountProductPriceRespVO>> getSecretAccountProductPricePage(@Valid SecretAccountProductPricePageReqVO pageReqVO) {
        PageResult<SecretAccountProductPriceDO> pageResult = secretAccountProductPriceService.getSecretAccountProductPricePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, SecretAccountProductPriceRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出全局产品定价（产品权限唯一 → 价格） Excel")
    @PreAuthorize("@ss.hasPermission('vos:secret-account-product-price:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportSecretAccountProductPriceExcel(@Valid SecretAccountProductPricePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<SecretAccountProductPriceDO> list = secretAccountProductPriceService.getSecretAccountProductPricePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "全局产品定价（产品权限唯一 → 价格）.xls", "数据", SecretAccountProductPriceRespVO.class,
                        BeanUtils.toBean(list, SecretAccountProductPriceRespVO.class));
    }

}